package Controller;

import javax.lang.model.type.NullType;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public class CenterController {
    Map<String, AreaController> areaControllerMap;

    public CenterController(){
        areaControllerMap = new HashMap<>();
    }

    // 在centerController上的AreaController实例
    static class AreaController extends Thread{
        public String address;
        public int socketPort;

        private Socket socket;
        private OutputStream output;
        private InputStream input;

        public AreaController(){

        }

        public void runClient() throws IOException{

            socket = new Socket(address, socketPort);
            input = socket.getInputStream();
            output = socket.getOutputStream();

        }

        public void send(String str, Function<Object, NullType> callback){
            try {
                output.write(str.getBytes());

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void run() {
            try {
                runClient();
            } catch (IOException e){

            }
        }
    }
}


